<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>修改业务名称</title>
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
	<script type="text/javascript" src="../resources/scripts/ext-base.js"></script>
	<script type="text/javascript" src="../resources/scripts/ext-basex.js"></script>
	<script type="text/javascript" src="../resources/scripts/ext-all-debug.js"></script>
	<script type="text/javascript" src="../resources/scripts/utils.js"></script>
	<link href="../resources/styles/ext-all.css" rel="stylesheet" type="text/css"/>
	<link href="../resources/styles/screen.css" rel="stylesheet" type="text/css" />
  </head>
  <body>
  </body>
  
<script type="text/javascript">
Ext.namespace("Report.Update");
Report.Update.panel = function (){
	this.updateBusinessName = new Ext.form.TextField({fieldLabel: '修改内容', width:130 });
	this.showBusinessName = new Ext.form.ComboBox({
        width :130,
        readOnly: true,
		fieldLabel: '业务名称',
		store : new Ext.data.JsonStore({
		   url:"../report/searchBusinessName.form",
		   autoLoad : true,
		   root:"result",
		   fields:["ID", "NAME"]
		}),
		valueField : 'ID',
		displayField :'NAME',
        mode: 'local',
		triggerAction :'all',
		emptyText :'请选择',
		selectOnFocus :true	
    });
	this.colseButton = new Ext.Button({
		text:"关闭",
		handler:function(){
			window.close();
		},
		scope:this
	});
	this.updateButton = new Ext.Button({
		text:"修改",
		handler: this.updateName,
		scope:this
	});
	this.delButton = new Ext.Button({
		text:"删除",
		handler: this.delName,
		scope:this
	});
	this.updatePanel = new Ext.form.FormPanel({
		title:'修改业务名称',
		autoWidth: true,
		labelWidth: 90,
		labelAlign: 'right',
		region: 'north',
		layout: 'table',
		height: 200,
		frame: true,
		layoutConfig: {columns: 1},
		style: {algin:'center'},
		items: [
					{layout: 'form',items: [this.showBusinessName ]},
					{layout: 'form',items: [this.updateBusinessName ]}
			]
		});
	Report.Update.panel.superclass.constructor.call(this,{
		width:280,
		height:200,
		modal:true,
		autoScroll:false,
		buttonAlign:'right',
		buttons:[this.updateButton, this.delButton, this.colseButton ],
		items:[this.updatePanel ],
		listeners:{
		}
	});
	
};
Ext.extend(Report.Update.panel, Ext.Window, {
	updateName: function(){
		var businessNameId = this.showBusinessName.getValue();
		var updateBusinessName = this.updateBusinessName.getValue();
		if (businessNameId == ''){
			alert("请选择要修改的业务名称!");
			return;
		} else if (updateBusinessName =='' ){
			alert("请输入修改内容!");
			return;
		} else {
			Ext.Ajax.request({
				url: '../report/checkBusinessName.form',
				method: 'POST',
				params: {
					name1: updateBusinessName
				},
				scope: this,
				success:function(rsp){
					var result = Ext.util.JSON.decode(rsp.responseText).result;
					// 如果业务名称已存在则提示，不存在则将输入的内容插入数据库中
					if (result == '1' || result == '2' || result == '3'){
						alert("您要修改的业务名称已在数据库中存在!");
						return;
					}else {
						Ext.Ajax.request({
							url: '../report/updateBusinessName.form',
							method: 'POST',
							params: {
								id: businessNameId,
								name: updateBusinessName
							},
							scope: this,
							success:function(rsp){
								alert("修改成功!");
								opener.location.reload();
								window.close();
							},
							failure:function(){
							}
						});
					}
				}
			});
		}
	},
	delName: function(){
		var businessNameId = this.showBusinessName.getValue();
		if (businessNameId == ''){
			alert("请选择要删除的业务名称!");
			return;
		} else {
			Ext.Ajax.request({
				url: '../report/delBusinessName.form',
				method: 'POST',
				params: {
					id: businessNameId
				},
				scope: this,
				success:function(rsp){
					alert("删除成功!");
					opener.location.reload();
					window.close();
				},
				failure:function(){
				}
			});
		}
	}
});

Ext.onReady(function(){
    Ext.QuickTips.init();
    Ext.BLANK_IMAGE_URL = '../resources/images/default/s.gif';
   	Report.Update.panel.instance = new Report.Update.panel();
    Report.Update.panel.instance.show();

});
</script>
</html>
